package com.hj.saapp.control.activity;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TableLayout;
import android.widget.TextView;

import com.hj.saapp.BCDApplication;
import com.hj.saapp.R;
import com.hj.saapp.common.utils.DisplayUtils;
import com.hj.saapp.control.activity.base.BaseActivity;

import static com.hj.saapp.R.id.table;
import static com.pgyersdk.views.b.p;

public class PrintActivity extends BaseActivity implements View.OnClickListener{

    String printInfo = "";
    String printInfos[] = null;
    TableLayout table;

    @Override
    public int getTitleById() {
        return R.string.print_title;
    }

    @Override
    public int getLayoutByid() {
        return R.layout.activity_print;
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void initView() {
        table = (TableLayout) findViewById(R.id.table);
    }

    @Override
    public void initData() {
        printInfo = getIntent().getStringExtra("data");
        printInfos = printInfo.split(";");
        TableLayout.LayoutParams row = new TableLayout.LayoutParams();
        TableLayout.LayoutParams head = new TableLayout.LayoutParams();
        TableLayout.LayoutParams foot = new TableLayout.LayoutParams();

        int line = DisplayUtils.dip2px(1);

        head.topMargin = line;
        head.leftMargin = line;
        head.rightMargin = line;
        View v = LayoutInflater.from(BCDApplication.getApp()).inflate(R.layout.view_head, null);
        table.addView(v,head);
        for (int i = 0; i < printInfos.length-1; i++) {


            String prints[] = printInfos[i].split(":");
            row.topMargin = line;
            row.leftMargin = line;
            row.rightMargin = line;
            View rowView = LayoutInflater.from(BCDApplication.getApp()).inflate(R.layout.view_row, null);
            TextView nameTv = (TextView) rowView.findViewById(R.id.nameTv);
            TextView numberTv = (TextView) rowView.findViewById(R.id.numberTv);
            nameTv.setText(prints[0]);
            numberTv.setText(prints[1]);
            table.addView(rowView,row);

        }
        String prints[] = printInfos[printInfos.length-1].split(":");
        foot.topMargin = line;
        foot.bottomMargin = line;
        foot.leftMargin = line;
        foot.rightMargin = line;
        View footView = LayoutInflater.from(BCDApplication.getApp()).inflate(R.layout.view_foot, null);
        TextView nameTv = (TextView) footView.findViewById(R.id.nameTv);
        TextView numberTv = (TextView) footView.findViewById(R.id.numberTv);
        nameTv.setText(prints[0]);
        numberTv.setText(prints[1]);
        table.addView(footView,foot);
    }
}
